// ActionScript file
import flash.events.*;

import mx.collections.*;
import mx.containers.Form;
import mx.containers.FormItem;
import mx.containers.HBox;
import mx.containers.Panel;
import mx.controls.Alert;
import mx.controls.Button;
import mx.controls.Image;
import mx.controls.LinkButton;
import mx.controls.TextInput;
import mx.effects.easing.*;
import mx.events.CalendarLayoutChangeEvent;
import mx.events.ItemClickEvent;
import mx.events.ListEvent;
import mx.events.MenuEvent;
import mx.events.ResizeEvent;
import mx.events.ValidationResultEvent;
import mx.managers.PopUpManager;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import mx.utils.StringUtil;
import mx.validators.*;

           private var img:Image;

			
 		// sets true if user has loggid in else sets false
 		
 		private var loginval:Boolean = false;
    
      // store the user access level after user logs in
		private var userAccess:String = "";

          private function handleLogin(event:ResultEvent):void {
			userAccess = event.result.loginid;
			//Alert.show(trace(userAccess!="failed").toString());
					
			if(userAccess!="failed") {
				// login success
				// hide failed login message, set login form to success state, show user menu
				loginFailedText.visible = false;
				loginSuccess.visible = true;
				username.visible=true;
				loginform.visible = false;
				username.text=event.result.loginid;
				type.text=event.result.type;
				myMenuAccount.visible = true;
				loginFailedText.visible = false;
				ProfileSrv.send();
				nenunnanu_log_in.visible=false;
				forgotpw.visible=false;
				button3.visible = false;
				button4.visible = false;
				loginval = true;
				
			}
			else
			{
				
				loginFailedText.visible = true;
				textinput2.text="";
				textinput1.text="";
				
			}
          }
          private function logout():void {
          	
			log_out.url= ENDPOINT_URL+"logout.php";
			log_out.send();
			currentState="home";
			loginFailedText.visible = false;
			loginSuccess.visible= false;
			loginform.visible=true;
			textinput2.text="";
		    textinput1.text="";
		    nenunnanu_log_in.visible=true;
		    forgotpw.visible=true; 
			button3.visible = true;
				button4.visible = true;
			loginval = false;
			username.text = "";
			myMenuAccount.visible = false;
			myMenuAccount0.visible = false;
		}
		public function feedbackresult():void
		{
			var msg:String = feedback.lastResult.toString()
			if(StringUtil.trim(msg) == 'sent')
			{
				contact_bt.label = "Submit";
				contact_bt.enabled = true;
				currentState = "contactsent";
			}
			else
			{
				Alert.show(msg);
			}
			
		}
			
           public function clickHandler(event:MouseEvent):void
           {
           	 panel1.visible = true;
           	
                p1.text = event.currentTarget.selectedItem.Name;
                p2.text = event.currentTarget.selectedItem.Location;
                p3.text = event.currentTarget.selectedItem.MobileNumber;
                p4.text = event.currentTarget.selectedItem.LandlineNumber;
                p5.text = event.currentTarget.selectedItem.Email;
                
            }  
           public function clickhandler():void
           {
           	//panel2.visible = true;
           	   var popup_todays:todays_blood_popup = new todays_blood_popup();
               
               PopUpManager.addPopUp(popup_todays,this,true);
                popup_todays.pa1.text = datagrid1.selectedItem.patient_full_name;
                popup_todays.pa2.text = datagrid1.selectedItem.bgroop;
                popup_todays.pa3.text = datagrid1.selectedItem.on_date;
                popup_todays.pa4.text = datagrid1.selectedItem.blood_volume;
                popup_todays.pa5.text = datagrid1.selectedItem.hospital_name;
                popup_todays.pa6.text = datagrid1.selectedItem.contact_no;
                popup_todays.pa7.text = datagrid1.selectedItem.land_line_no;
                popup_todays.pa8.text = datagrid1.selectedItem.purpose;
//                popup_todays.pa9.text = datagrid1.selectedItem.MobileNumber;
                popup_todays.pa10.text = datagrid1.selectedItem.patient_address;
                popup_todays.pa11.text = datagrid1.selectedItem.area;
                popup_todays.pa12.text = datagrid1.selectedItem.age;                
           }

            // Event handler function to print a message
            // describing the selected Button control.  
                     
            private function login():void
            {
            	Alert.show(loginvalidate.lastResult.toString());
            	currentState = 'home';
            	
            }   
            private function search():void
            {
            	if(search1.lastResult.item== "No results found")
            	{
            		Alert.show("No results found");
            		currentState = 'home';
            		
            	}
            	else
            	{            		
                 	currentState = 'searchresults';
                 	//E_Blood_Request.visible="false";
            	    searchresults.dataProvider = search1.lastResult.item;
            	}
            	
            }
            private function register1():void
            {
            	          	
            	Alert.show(registration.lastResult.toString());
            	currentState = 'home';
            	
            }
            //function to send contacts 
            public var email_type:String;
            
            private function send_contacts():void
            {
            	
            	if(email_type!="Gmail")
            	email_type = "Yahoo";
            	var params:Object = {};
				if(email_type == 'Gmail')
				{
					params['uname'] = contacts_uname_g.text;
					params['pass'] = contacts_pass_g.text;
				}
				else 
				if(email_type == 'Yahoo')
				{
					params['uname'] = contacts_uname_y.text;
					params['pass'] = contacts_pass_y.text;
				}
				params['email_type'] = email_type;
				contacts_grab.send(params);
            }
            //function to get contacts
            public var tempArr:Array ;
            public var popup_contacts:contacts_popup;
            private function get_contacts():void
            {
            	  popup_contacts = new contacts_popup();
            	//tempArr = contacts_grab.lastResult.toLocaleString();
            	if(contacts_grab.lastResult.item.message=="Error")
            	{
            		Alert.show("Invalid Username/Password");
            	}
            	else
            	if(contacts_grab.lastResult.item.message=="true")
            	{
            		
               
               PopUpManager.addPopUp(popup_contacts,this,true);
            	   	popup_contacts.Gcontacts.dataProvider = contacts_grab.lastResult.item;
            	   	popup_contacts.Send_contact_msg.addEventListener(MouseEvent.CLICK, get_selected);
            	}
            	//Alert.show(contacts_grab.lastResult.toString());
            } 
            //to get the selected contacts
            private function get_selected(event:MouseEvent):void{
            	var parameters_contact:Object ={};
            	parameters_contact['contacts']= popup_contacts.Gcontacts.selectedItems.toString();
            	parameters_contact['message']= popup_contacts.contact_message.text;
            	Tellafriend_service.request=parameters_contact;
          	    Tellafriend_service.send();
            	//Alert.show(popup_contacts.Gcontacts.selectedItems.toString());
            }
           // to get contacts result status message 
           private function result_contacts():void
           {
           	Alert.show(Tellafriend_service.lastResult.toString());
           }
            //function set contacts_email 
            private function contacts_email(event:ItemClickEvent):void
            {
            	email_type = event.label;
            }
           [Bindable]
            private var validatorArr:Array;
             private var validatorArr1:Array;
             private var validatorArr2:Array;
             private var validatorArr6:Array;
             private var validatorArr3:Array;
              private var validatorArr4:Array;
              private var article:mx.rpc.http.HTTPService=new mx.rpc.http.HTTPService;
            //  private var events:mx.rpc.http.HTTPService=new mx.rpc.http.HTTPService;
             
              
              public var selectedItem:Object;

              // private var gateway:HTTPService = new HTTPService();
              public function on_fault_msg():void
              {
              	Alert.show('Error In Connection');
              }
			private var String_Validator:StringValidator;

            private function initfunction():void
            {
            	
            	//register.addEventListener(FlexEvent.BUTTON_DOWN,register1);
            	loginvalidate.url=ENDPOINT_URL+"loginvalidate.php";
            	 TextScroller.start();

            	tellfriendsend.url=ENDPOINT_URL+"tellfriend.php";
            	feedback.url=ENDPOINT_URL+"sendfeedback.php";
            	projectsSrv1.url=ENDPOINT_URL+"places.php";
            	Blood_Requests.url =ENDPOINT_URL+"blood_post.php";
            	Post_Blood.url=ENDPOINT_URL+"blood_post.php";
            	projectsSrv2.url=ENDPOINT_URL+"places.php";
            	registration.url=ENDPOINT_URL+"registration.php";
            	search1.url=ENDPOINT_URL+"search.php";
            	Blood_Requests_Edit.url=ENDPOINT_URL+"blood_post.php";
            	//articles 
            	deletearticle.url = ENDPOINT_URL+"articles.php";
            	article.url=ENDPOINT_URL+"articles.php";
            	get_articles.url = ENDPOINT_URL+"getarticles.php";
            	display_article.url = ENDPOINT_URL+"getarticles.php";
            	recent_artilce.url = ENDPOINT_URL+"getarticles.php";
            	search_article.url = ENDPOINT_URL+"getarticles.php";
            	var params_recent:Object=new Object();
            	params_recent['recent'] = 'true';
            	recent_artilce.request = params_recent;
            	recent_artilce.send();
            	//events
            	events.url = ENDPOINT_URL+"articles.php";
            	var params_event:Object=new Object();
            	//events.resultFormat="e4x";
            	events.addEventListener(ResultEvent.RESULT,event_display);
            	params_event['name'] = "events";
            	events.request = params_event;
            	events.send();
            	//contacts
            	 
            	contacts_grab.url = ENDPOINT_URL+"contacts_grab.php";
            	Tellafriend_service.url = ENDPOINT_URL+"send_msg_cts.php";
            	MYACCOUNT.url = ENDPOINT_URL+"myaccount.php";
            	Em_Blood_Requests.url = ENDPOINT_URL+"blood_post.php";
            	forgotpassword.url = ENDPOINT_URL+"forgotpassword.php";
            	ProfileSrv.url = ENDPOINT_URL+"profile.php";
            	login_as_nenunnanu.url=ENDPOINT_URL+"loginvalidate.php";
            	articlespost.url = ENDPOINT_URL+"articles.php";
            	projectsSrv1.send();
            	Blood_Requests.send();
            	var params_article:Object=new Object();
            	article.resultFormat="e4x";
            	article.addEventListener(ResultEvent.RESULT,article_display);
            	
            	article.method="POST";
            	params_article['name']="article";
            	article.request=params_article;
            	article.send();
            	        	
            	TextScroller.start();
            	//get articles
                get_articles.send();
            	Em_Blood_Requests.send();
            	//article_date
            	
            	
            	
            	//validation for registration
            	validatorArr = new Array();
                validatorArr.push(Name_stringValidator);
                validatorArr.push(Gender_numberValidator);
                validatorArr.push(MaritalStatus_numberValidator);
                validatorArr.push(Email_emailValidator);
                validatorArr.push(MobileNumber_phoneNumberValidator);
                validatorArr.push(stringDateV);
                validatorArr.push(Password_stringValidator);
                validatorArr.push(CPassword_stringValidator);
                validatorArr.push(BloodGroup_numberValidator);
                validatorArr.push(District_numberValidator);
                validatorArr.push(Location_numberValidator);
              
                
                validatorArr1 = new Array();
                validatorArr1.push(B_Name);
                validatorArr1.push(B_Age);
                //validatorArr1.push(D_Blood_Group);
                validatorArr1.push(B_On_Date);
                validatorArr1.push(B_Contact_No);
                validatorArr1.push(B_Blood_Need);
                validatorArr1.push(GenderNumberValidator);
                //validation for blood request
                validatorArr2 = new Array();
                validatorArr2.push(T_name);
                validatorArr2.push(T_email1);
                //validation for feedback
                 validatorArr3 = new Array();
                 validatorArr3.push(c1_email);
                validatorArr3.push(c1_subject);
                validatorArr3.push(c1_feedback);
                
                // validator for login form
				validatorArr6 = new Array();
				validatorArr6.push(val_username); 
				validatorArr6.push(val_password);               
                
                validatorArr4 = new Array();
                validatorArr4.push(district);
                validatorArr4.push(city);
                validatorArr4.push(b_group);
                
                
                
//                gateway.url = ENDPOINT_URL+"blood_post.php";
//            	gateway.resultFormat = "e4x";
//                gateway.method = "POST";
//            	gateway.showBusyCursor = "true"
//				gateway.addEventListener(ResultEvent.RESULT, result_post);
           }   
           
           //function to post artcle 
           public function Post_Artcle():void{
           		var parameters:Object={} ;
                	parameters['Message'] = richtexteditor0.text;
                	parameters['Title'] = articletitle.text;
                	parameters['action'] = post_article0.label;
                	
                	if(editid!= null)
                	{
                		parameters['editid'] = editid;
                	}
                	post_article0.label = "Processing..";
                	post_article0.enabled = false;
                	articlespost.request = parameters;
                	articlespost.send();
           }
           
           private function validateForm(evt:MouseEvent):void {
           	    if(register.label=="Register")
           	    {
           	    	validatorArr.pop();
           	    }
                var validatorErrorArray:Array = Validator.validateAll(validatorArr);
                var isValidForm:Boolean = validatorErrorArray.length == 0;
                
                
                if (isValidForm) {
                	var parameters:Object={} ;
                	parameters['Name']=Name.text;
                	parameters['Gender']=Gender.text;
                	parameters['MaritalStatus']=MaritalStatus.text;
                	parameters['Password']=Password.text;
                	parameters['BloodGroup']=BloodGroup.text;
                	parameters['Email']=Email.text;
                	parameters['dob']=dob.text;
                	parameters['District']=District.text;
                	parameters['Location']=Location.text;
                	parameters['Address']=Address.text;
                	parameters['MobileNumber']=MobileNumber.text;
                	parameters['LandlineNumber']=LandlineNumber.text;
                                
                	 if(register.label=="Register Me")
           	    {
                	
                	parameters['type']="donor";
                    
                }
                else if(register.label=="Register")
                {
                	parameters['type']="nenunnanu";
                }
                if(Password.text != ConfirmPassword.text)
                 	{
                 		Alert.show("Password and Confirm Password donot match","Invalid form...", Alert.OK);
                 	}
                 	else
                 	{
		                registration.request = parameters;
		                registration.send();
                 	}
                } else {
                    var err:ValidationResultEvent; 
                    var errorMessageArray:Array = [];
                    for each (err in validatorErrorArray) {
                        var errField:String = FormItem(err.currentTarget.source.parent).label
                        errorMessageArray.push(errField + ": " + err.message);
                    }
                    if(Password.text != ConfirmPassword.text)
                 	{
                 		errorMessageArray.push("Password and Confirm Password donot match");
                 	}
                    Alert.show(errorMessageArray.join("\n\n"), "Invalid form...", Alert.OK);
                }
            }
            private function submit_edit():void
            {
            	
            }
            private function validateForm1(evt:MouseEvent):void {
            	//Alert.show("hello");
                var validatorErrorArray1:Array = Validator.validateAll(validatorArr1);;
                var isValidForm:Boolean = validatorErrorArray1.length == 0;
               // Alert.show(validatorErrorArray1.toString());
                
                
                if (isValidForm) {
                	var temp:String = ''; 
                	var parameters:Object={} ;
                	parameters['D_Name']=D_Name.text;
                	parameters['D_Age']=D_Age.text;
                	parameters['D_Blood_Group']=D_Blood_Group.text;
                	parameters['D_On_Date']=D_On_Date.text;
                	parameters['D_Blood_Need']=D_Blood_Need.text;
                	parameters['D_Contact_No']=D_Contact_No.text;
                	parameters['D_LL_Number']=D_LL_Number.text;
                	parameters['D_Location']=D_Location.text;
                	parameters['D_Hospital']=D_Hospital.text;
                	parameters['D_Address']=D_Address.text;
                	parameters['D_Purpous']=D_Purpous.text;
                	parameters['Submit']=Submit.label;
                	var actiontype:String = Submit.label;
                	if(actiontype != 'Post')
                	parameters['R_Blood_Code']=input_item1.text;
                	Post_Blood.request = parameters;
                    Post_Blood.send();
                } else {
                	 var err:ValidationResultEvent;
                    var errorMessageArray:Array = [];
                    for each (err in validatorErrorArray1) {
                        var errField:String = FormItem(err.currentTarget.source.parent).label
                        errorMessageArray.push(errField + ": " + err.message);
                    }
                     Alert.show(errorMessageArray.join("\n\n"), "Invalid form...", Alert.OK);
                         }
            }
            private function validateForm2(evt:MouseEvent):void {
                var validatorErrorArray2:Array = Validator.validateAll(validatorArr2);;
                var isValidForm:Boolean = validatorErrorArray2.length == 0;
                
                
                if (isValidForm) {
                    tellfriendsend.send();
                } else {
                	 var err:ValidationResultEvent;
                    var errorMessageArray:Array = [];
                    for each (err in validatorErrorArray2) {
                        var errField:String = FormItem(err.currentTarget.source.parent).label
                        errorMessageArray.push(errField + ": " + err.message);
                    }
                     Alert.show(errorMessageArray.join("\n\n"), "Invalid form...", Alert.OK);
                               }
            }
             private function validateForm3(evt:MouseEvent):void {
                var validatorErrorArray3:Array = Validator.validateAll(validatorArr3);;
                var isValidForm:Boolean = validatorErrorArray3.length == 0;
                
                
                if (isValidForm) {
                	contact_bt.label = "Processing..";
                	contact_bt.enabled = false;
                   feedback.send();
                } else {
                	 var err:ValidationResultEvent;
                    var errorMessageArray:Array = [];
                    for each (err in validatorErrorArray3) {
                        var errField:String = FormItem(err.currentTarget.source.parent).label
                        errorMessageArray.push(errField + ": " + err.message);
                    }
                     Alert.show(errorMessageArray.join("\n\n"), "Invalid form...", Alert.OK);
                                }
            }
            private function validatesearch()
            {
            	 var validatorErrorArray4:Array = Validator.validateAll(validatorArr4);;
                var isValidForm:Boolean = validatorErrorArray4.length == 0;
                
                
                if (isValidForm) {
                    search1.send();
                }
                else {
                	 var err:ValidationResultEvent;
                    var errorMessageArray:Array = [];
                    for each (err in validatorErrorArray4) { 
                        var errField:String = FormItem(err.currentTarget.source.parent).label
                        errorMessageArray.push(err.message);
                    }
                     Alert.show(errorMessageArray.join("\n\n"), "Invalid form...", Alert.OK);
                                }
            	
            }
            private function profileResult(event:ResultEvent)
            {
            	if(currentState=="profile")
            	{
            		getProfile();
            	}
            	
            }
            private function submit_myaccount():void
            {
            	
            	if(Update_profile.label=="Change Password")
            	{
            		var parameters:Object={} ;
                	parameters['Old_Pass']=Ch_Old_Pass.text;
                	parameters['New_Pass']=Ch_New_Pass.text;
                	parameters['Confirm_Pass']=Ch_Confirm_Pass.text;
                	parameters['Type']= "ChangePass";
                	MYACCOUNT.request = parameters;
                	MYACCOUNT.send();
            	}
            	else if(Update_profile.label=="Edit")
            	{
            		currentState="editprofile";
            		getProfileEdit();
            	}
            	else 
                if( Update_profile.label == "Update")
                {
                	var parameters2:Object={} ;
                	parameters2['Name']=Ed_Profile.text;
                	parameters2['Gender']=Ed_Gender.text;
                	parameters2['M_Status']=Ed_M_Status.text;
                	//parameters2['Email']=Ed_Email_Id.text;
                	parameters2['Dob']=Ed_Dob.text;
                	parameters2['BloodGroup']=Ed_BloodGroup.text;
                	parameters2['MobileNo']=Ed_MobileNo.text;
                	parameters2['LL_No']=Ed_LLNo.text;
                	parameters2['Address']=Ed_Address.text;
                	parameters2['District']=Ed_District.text;
                	parameters2['Location']=Ed_Location.text;
                	parameters2['Type']= "Profile_Update";
                	MYACCOUNT.request = parameters2;
                	MYACCOUNT.send();
                	ProfileSrv.send();
                	
                	
                } 
                else 
                if( Update_profile.label == "Submit")
                {
                	var parameters1:Object={} ;
                	parameters1['Old_Pass']=Ch_Old_Pass.text;
                	parameters1['New_Pass']=Ch_New_Pass.text;
                	parameters1['Confirm_Pass']=Ch_Confirm_Pass.text;
                	parameters1['Donated_date']=Donated_date.text;
                	parameters1['Type']= "LastDonated";
                	MYACCOUNT.request = parameters1;
                	MYACCOUNT.send();
                	ProfileSrv.send();
                	//Alert.show(Ch_Old_Pass.text);
                }
                 if(Update_profile.label != "Edit")
                 {
                 	
                	
                 }
            }
            //set parameters for updating profile
            public function set_paramenters_profile():void
            {
            	
                	//return (parameters2);
            }
            private function My_Account_Details():void
            {
            	   ProfileSrv.send();
             	var alert_message:String = MYACCOUNT.lastResult.alert;	
            	
            	if(MYACCOUNT.lastResult.msg == 'true')
            	{
 //           		getProfile();
 //           		getProfileEdit();
            		currentState = 'profile';
            		if(MYACCOUNT.lastResult.alert == "Password Updated Successfully")
            		{
            			set_Myaccount_Null();
            		}
            		if(MYACCOUNT.lastResult.alert == "Details Added Successfully")
            		{
            			set_Myaccount_Null();
            			Donated_date.text='';
            		}
            		
            	}
            	else 
            	if(MYACCOUNT.lastResult.msg == 'false')
            	{
					alert_message += "\n Please Re-type Password";
            	}
            	Alert.show(alert_message,'Message');
            }
            
            
            private function set_Myaccount_Null():void
            {
            	    Ch_Old_Pass.text = '';
            		Ch_New_Pass.text = '';
            		Ch_Confirm_Pass.text = '';
            }
            private function validateforgotpw(event:MouseEvent)
            {
            	      if(forgot_pw.text == "")
            	     {
            	     	Alert.show("please enter email-id");
            	     }    
            	     else
            	     {
            	        forgotpassword.send();
            	     }
            }    
           
		

            private function buttonclick(event:ItemClickEvent):void
            {
            	switch(event.index)
            	{
            		case 0:
            		{
            			currentState="home";
            			 	break;
            		}
            		case 1:
            		{
            			currentState="aboutus";
            			break;
            		}
            		case 2:
            		{
            		    currentState="articles";
            		    recent_article();
            			break;	
            		}
            		case 3:
            		{
            			currentState="gallery";
            			break;
            		}
            		case 4:
            		{
            			currentState="faq1";
            			break;
            		}
            	}
            		
            	
            }
          	
           
            private function blood():void
            {
            	
            	Alert.show(Post_Blood.lastResult.toString());
            }
            private function itemClickHandler(event:MenuEvent):void {
            	//Alert.show(event.item.@label);
            	
            		if(event.item.@label == "Blood in Emergency")
            		
            		{
            			currentState="emergency";
            			datagrid12.dataProvider = Em_Blood_Requests.lastResult.item;
            		}
            		else if(event.item.@label == "Physically Challenged")
            	    {
            		currentState = 'physicallychallenged';
            		
            	    }
            	    else if(event.item.@label == "RuralDevelopment")
            	    {
            		currentState = 'ruraldevelopment';
            		
            	    }
            	     else if(event.item.@label == "Hut Needy")
            	    {
            		currentState = 'hutneedy';
            		
            	    }
            	     else if(event.item.@label == "Clothes")
            	    {
            		currentState = 'clothes';
            		
            	    }
            	     else if(event.item.@label == "Green")
            	    {
            		currentState = 'green';
            		
            	    }
            	     else if(event.item.@label == "Traffic")
            	    {
            		currentState = 'traffic';
            		
            	    }
            	     else if(event.item.@label == "Education")
            	    {
            		currentState = 'education';
            		
            	    }
            	    else if(event.item.@label == "Things to be done")
            	    {
            		currentState = 'thingstobedone';
            		
            	    }
            	     else if(event.item.@label == "About Blood Donation")
            	    {
            		currentState = 'blooddonation';
            		
            	    }
            	    else if(event.item.@label == "Profile")
            	    {
            		currentState = 'profile';
            		getProfile();
            		
            	    }
            	    else if (event.item.@label == "Change Password")
            	    {
            	    	currentState = "changepass";
            	    }
            	    else if (event.item.@label == "Last Donated Date")
            	    {
            	    	currentState = "lastdonateddate";
            	    }
            	    else if (event.item.@label == "Write Article")
            	    {
            	    	currentState = "writearticle";
            	    	richtexteditor0.text = '';
			            		articletitle.text = '';
			            		post_article0.label = "Post Article";
			            		post_article0.enabled = true;
            	    }
            		
            }
       
        public function getProfile():void
        {
        	//Alert.show(ProfileSrv.lastResult.toString());
        	Ac_Profile.text = ProfileSrv.lastResult.item.Name;
        	Ac_Location.text = ProfileSrv.lastResult.item.Location;
        	Ac_Address.text = ProfileSrv.lastResult.item.Address;
        	Ac_District.text = ProfileSrv.lastResult.item.District;
        	Ac_BloodGroup.text = ProfileSrv.lastResult.item.BloodGroup;
        	Ac_Dob.text = ProfileSrv.lastResult.item.Dob;
        	Ac_Email_Id.text = ProfileSrv.lastResult.item.Email;
        	Ac_Gender.text = ProfileSrv.lastResult.item.Gender;
        	Ac_LLNo.text = ProfileSrv.lastResult.item.LandlineNumber;
        	Ac_M_Status.text = ProfileSrv.lastResult.item.MaritalStatus;
        	Ac_MobileNo.text = ProfileSrv.lastResult.item.MobileNumber;
        }
        public function getProfileEdit():void
        {
        	Ed_Profile.text = ProfileSrv.lastResult.item.Name;
        	Ed_Location.text = ProfileSrv.lastResult.item.Location;
        	Ed_Address.text = ProfileSrv.lastResult.item.Address;
        	Ed_District.text = ProfileSrv.lastResult.item.District;
        	Ed_BloodGroup.text = ProfileSrv.lastResult.item.BloodGroup;
        	Ed_Dob.text = ProfileSrv.lastResult.item.Dob;
//        	Ed_Email_Id.text = ProfileSrv.lastResult.item.Email;
        	Ed_Gender.text = ProfileSrv.lastResult.item.Gender;
        	Ed_LLNo.text = ProfileSrv.lastResult.item.LandlineNumber;
        	Ed_M_Status.text = ProfileSrv.lastResult.item.MaritalStatus;
        	Ed_MobileNo.text = ProfileSrv.lastResult.item.MobileNumber;
        }
	 private var bloodgroup:Array= 
            [{label:"A+", data:"A+"},
            {label:"A-", data:"A-"},
            {label:"B+", data:"B+"},
            {label:"B-", data:"B-"},
            {label:"AB+",data:"AB+"},
            {label:"AB", data:"AB"},
            {label:"O+", data:"O+"},
            {label:"O-", data:"O-"},
            {label:"A1+", data:"A1+"},
            {label:"A1-", data:"A1-"},
            {label:"A2+", data:"A2+"},
            {label:"A2-", data:"A2-"},
            {label:"A1B+", data:"A1B+"},
            {label:"A1B-", data:"A1B-"},
            {label:"A2B+", data:"A2B+"},
            {label:"A2B-", data:"A2B-"},
            {label:"Bombay Blood Group", data:"Bombay"},
                ];
                           
              [Bindable]                      
         public var bloodgroup1:ArrayCollection;
         private function initData():void
         {
         bloodgroup1 = new ArrayCollection(bloodgroup);
          }
            

	// Display a selected item's label field and index for change events.
         private function changeEvt(event:Event):void {
         	    var parentid:Object = new Object();
                  
                 parentid.parentid = event.currentTarget.selectedItem.data;
               
                 projectsSrv2.send(parentid);    
             
                  
         }

         public function footerLinks(link:int):void{
         	switch(link)
            	{
            		case 1:
            		{
            			currentState="home";
            			break;
            		}
            		case 2:
            		{
            			currentState="reg";
            			
            			break;
            		}
            		case 3:
            		{
            			currentState="faq1";
            			break;
            		}
            		case 4:
            		{
            		    currentState="aboutus";
            			break;	
            		}
            		case 5:
            		{
            			currentState="contactus";
            			break;
            		}
            	}
            
         }
         private function PopUp_Emergency():void {
               var popup_title:emergency_popup = new emergency_popup();
               
               PopUpManager.addPopUp(popup_title,this,true);
               	popup_title.P_Name.text = datagrid12.selectedItem.patient_full_name;
            	popup_title.B_Group.text = datagrid12.selectedItem.bgroop;
            	popup_title.B_Required.text = datagrid12.selectedItem.on_date;
                popup_title.A_B_N.text = datagrid12.selectedItem.blood_volume;
                popup_title.H_Name.text = datagrid12.selectedItem.hospital_name;
                popup_title.M_Name.text = datagrid12.selectedItem.contact_no;
                popup_title.LL_Number.text = datagrid12.selectedItem.land_line_no;
                popup_title.E_Pur.text = datagrid12.selectedItem.purpose;
                popup_title.E_Address.text = datagrid12.selectedItem.patient_address;
                popup_title.E_Location.text = datagrid12.selectedItem.area;
                popup_title.E_Age.text = datagrid12.selectedItem.age; 
            }

          function explode(separator:String, string:String)
          {

			var list = new Array();
		
			if (separator == null) return false;
			if (string == null) return false;
		
			var currentStringPosition = 0;
			while (currentStringPosition<string.length) {
				var nextIndex = string.indexOf(separator, currentStringPosition);
				if (nextIndex == -1) break;
				var word = string.slice(currentStringPosition, nextIndex);
				list.push(word);
				currentStringPosition = nextIndex+1;
			}
			if (list.length<1) {
				list.push(string);
			} else {
				list.push(string.slice(currentStringPosition, string.length));
			}
			return list;
		}
		 
//		 public function get_emergency():void
//		 {
//		 	E_Blood_Request.visible = true;
//		 		P_Name.text = datagrid12.selectedItem.patient_full_name;
//            	B_Group.text = datagrid12.selectedItem.bgroop;
//            	B_Required.text = datagrid12.selectedItem.on_date;
//                A_B_N.text = datagrid12.selectedItem.blood_volume;
//                H_Name.text = datagrid12.selectedItem.hospital_name;
//                M_Name.text = datagrid12.selectedItem.contact_no;
//                LL_Number.text = datagrid12.selectedItem.land_line_no;
//                E_Pur.text = datagrid12.selectedItem.purpose;
//                E_Address.text = datagrid12.selectedItem.patient_address;
//                E_Location.text = datagrid12.selectedItem.area;
//                E_Age.text = datagrid12.selectedItem.age; 
//		 }
         public function result_post():void
            {
            	var result:String;
            	result = Post_Blood.lastResult.toString();
            	var samplearr:Array = explode(',',result);
            	var sample:String = samplearr[0];
            	var Code:String = 'Blood Request Code :\t'+samplearr[1]+'  ';
            	if(sample == 'true')
            	{
            		var message:String = 'Your Bood Request Posted Successfully \n\n';
            		Alert.show(message+Code);
            		currentState = "home";
            		Blood_reset();
            		Blood_Requests.send();
            		blood_request_data();
            	}
            	else
            	if(sample == 'false')
            	   	Alert.show('Invalid Entry');
            	   	
            	if(sample == 'true1')
            	{
            		var message1:String = 'Your Bood Request Updated Successfully \n\n';
            		Alert.show(message1);
            		currentState="home";
            		Blood_reset();
            		D_Cancel.visible = false;
            	}
            	
            }
           public var panel_new:Panel;
           public var form_new:Form;
           public var form_item1:FormItem;
           public var form_item2:FormItem;
           public var input_item1:TextInput;
          
           
            public function click_blood_request():void
            {
            	 //var ss:HTTPService = new HTTPService();
            	//var sss:HTTPRequestMessage = new HTTPRequestMessage();
            	panel_new = new Panel();
            	form_new = new Form();
            	form_item1 = new FormItem();
            	input_item1 = new TextInput();
            	form_item2 = new FormItem();
            	var h_box:HBox = new HBox();
            	var b_1:Button= new Button();
            	var b_2:Button = new Button();
            	//ss.url = ENDPOINT_URL+"blood_post.php";
            	//ss.resultFormat = "e4x";
            	//ss.method = "POST";
            	//ss.showBusyCursor = "true"
				//ss.addEventListener(ResultEvent.RESULT, result_post);
            	panel_new.title = "Enter Your Blood Request Code";
            	panel_new.height = 140;
            	panel_new.id = "sample112";
            	panel_new.width = 310;
            	panel_new.x = 270;
            	panel_new.y = 210;
            	form_new.height=95;
            	form_new.width=270;
            	form_new.x=0;
            	form_new.y=10;
            	form_item1.label = "Request Code";
            	form_item1.width = 222;
            	input_item1.id = "R_Blood_Code";
            	input_item1.width = 121;
            	h_box.width = 222;
            	form_item2.setStyle("paddingLeft",50);
            	b_1.label="Submit";
            	b_2.label= "Cancel";
            	b_2.addEventListener(MouseEvent.CLICK,Blood_Edit_Reset);
            	b_1.addEventListener(MouseEvent.CLICK,Blood_Request_Send);
            	form_item2.addChild(b_1);
            	h_box.addChild(form_item2);
            	h_box.addChild(b_2);
            	form_item1.addChild(input_item1);
            	form_new.addChild(form_item1);
            	form_new.addChild(h_box);
            	panel_new.addChild(form_new);
            	panel_new.setStyle("addedEffect",image_removedEffect);
            	panel_new.setStyle("removedEffect", effect_blood_request);
            	//panel_new.setStyle("x",100);
            	PopUpManager.addPopUp(panel_new, this, true);
                PopUpManager.centerPopUp(panel_new);

            	// Application.application.addChild(panel_new);
            	
            }
            
            
            public function Blood_Request_Send(eve:MouseEvent):void
            {
            	//Alert.show("ssss");
            	var params:Object = {};
				
				params['R_Blood_Code'] = input_item1.text;
				params['R_code'] = 123;
				//params.parameter2 = "value2"; 
//            	ss.send(params);
				//Blood_Requests_Edit.request = params;
            	Blood_Requests_Edit.send(params);
            }
    	public function blood_request_data():void
    	{ 
    		datagrid1.dataProvider = Blood_Requests.lastResult.item;
    	}
    	public function blood_request_Emg():void
    	{
    		
    	}
    	public function Blood_Edit_Reset(event:MouseEvent):void
    	{         
    		PopUpManager.removePopUp(panel_new);
    		 // Application.application.removeChild(panel_new);
//    				Request_Blood.visible = false;
    				Blood_reset();
            		Submit.label = 'Post';
    				D_Cancel.visible = false;
    	}
    	public function login_validate(eve:MouseEvent):void
    	{
    		 var validatorErrorArray6:Array = Validator.validateAll(validatorArr6);;
                var isValidForm:Boolean = validatorErrorArray6.length == 0;
                
                
                if (isValidForm) {
                 loginvalidate.send();
                } else {
                	 
                                }
//    		if(textinput1.text != '' && textinput2.text!="")
//    		loginvalidate.send();
    	}
    	public function Blood_reset():void
    	{
    		D_Name.text = '';
            		D_Age.text = '';
            		D_Blood_Group.selectedIndex= -1;
            		D_On_Date.text = '';
            		D_Blood_Need.text = '';
            		D_Contact_No.text = '';
            		D_LL_Number.text = '';
            		D_Location.text = '';
            		D_Hospital.text = '';
            		D_Address.text = '';
            		D_Purpous.text = '';
//            		R_Blood_Code.text = '';
    	}
    	public function blood_request_edit():void
    	{
    		var result:String;
            	result = Blood_Requests_Edit.lastResult.toString();
            	var samplearr:Array = explode(',',result);
            	var sample:String = samplearr[0];
            	
            if(sample == 'true')
            	{
            		var Blood_Index:int = getBloodGroupIndex(samplearr[3]);
            	var DateArray:Array = explode('-',samplearr[4]);
            	var TempDate:String = DateArray[1]+'/'+DateArray[2]+'/'+DateArray[0];
            		//Alert.show(Blood_Index);
            		D_Name.text = samplearr[1];
            		D_Age.text = samplearr[2];
            		D_Blood_Group.selectedIndex = Blood_Index;  
            		D_On_Date.text = TempDate;
            		D_Blood_Need.text = samplearr[5];
            		D_Contact_No.text = samplearr[6];
            		D_LL_Number.text = samplearr[7];
            		D_Location.text = samplearr[8];
            		D_Hospital.text = samplearr[9];
            		D_Address.text = samplearr[10];
            		D_Purpous.text = samplearr[11];
            		Submit.label = 'Update';
            		D_Cancel.visible = true;
            		PopUpManager.removePopUp(panel_new);
            		//Application.application.removeChild(panel_new);
            		//Request_Blood.visible = false;
            	}
            	else
            	if(sample == 'false')
            	{
            		Alert.show('Invalid Request Code');
            	}
            	
    	}
    	//find label index value in bloodgroup1 array 
    	private var _selectedValue:String;

    	 public function getBloodGroupIndex(Label_Blood:String)
    	 {
    	 	
    	 	for (var i:int=0; i<this.bloodgroup1.length; i++) {
                  // Get this item's data 
                  var item:String = this.bloodgroup1[i].data;
 
                  // Check if is selectedValue 
                  if(item == Label_Blood) {
                     // Yes, set selectedIndex 
                     var Blood_selectedIndex:int = i;
                     break;
                  }
               }
               return(Blood_selectedIndex);

    	 	
    	 }
    	 
            private function tileList_itemClick(evt:ListEvent):void {
                img = new Image();
                // img.width = 300;
                // img.height = 300;
                
                img.maintainAspectRatio = true;
                img.addEventListener(Event.COMPLETE, image_complete);
                img.addEventListener(ResizeEvent.RESIZE, image_resize);
                img.addEventListener(MouseEvent.CLICK, image_click);
                img.source = evt.itemRenderer.data.@fullImage;
                img.setStyle("addedEffect", image_addedEffect);
                img.setStyle("removedEffect", image_removedEffect);
                PopUpManager.addPopUp(img, this, true);
            }

            private function image_click(evt:MouseEvent):void {
                PopUpManager.removePopUp(evt.currentTarget as Image);
             }

            private function image_resize(evt:ResizeEvent):void {
                PopUpManager.centerPopUp(evt.currentTarget as Image);
            }

            private function image_complete(evt:Event):void {
                PopUpManager.centerPopUp(evt.currentTarget as Image);
            }
            private function article_display(e:ResultEvent)
            {
            	for each(var property:XML in e.result.item) {
                // Create an Array of unique names.
                
               //  var tf:Text = new Text();
                // var label:Label = new Label();
                 var linkbutton:LinkButton =new LinkButton();
                
                 var hbox12:HBox = new HBox();
                 hbox12.styleName=""
                 //hbox12.addChild(tf);
                // hbox12.addChild(label);
                
                 vbox2.addChild(hbox12);
                // tf.text = property.title;
                 linkbutton.styleName="articles";
                 linkbutton.addEventListener(MouseEvent.CLICK,article_popup(property.id,property.title,property.content,property.writtenby)); 
                 linkbutton.label = property.title;
                   
                hbox12.addChild(linkbutton);
                
                         	
            }
             for each(var event:XML in e.result.events) {
             var event_name:String= new String();
          	
             event_name+= event.description;
             event_name+="&#xa;";
             TextScroller.text=event_name;
             	
              
            }
            Alert( event_name);	
            }
            
            public function event_display(e:ResultEvent):void
            {
            	var event_name:String= new String();
            	var temp:String; 
            	 for each(var event:XML in e.result.item) {
            	 	temp = event.events;
            	 	  temp = string_trim(temp);
            	 	
		             event_name += temp;
		             event_name +="\n\n";
		             TextScroller.text=event_name;
		            }
           		
            	
            }
            
            public function string_trim(str:String)
            {
            	var leng:int = str.length; 
            	var div:int = 48;
            	var sub:int = leng/div;
            	var i:int = 0;
            	var div1:int =0 ;
            	for(i;i<=sub;i++)
            	{
            		
            		if(i == 0)
            		{
            			var res = str.substr(0,div);
            		}
            		else
            		{
            			div1 =div*(i);
            			res += '\n'+str.substr(div1,div);
            		}
            		
            	}
//            	var res = str.substr(0,45);
//            		 res += str.substr(45,45);
//            	Alert.show(res.toString());
            	return res;
            }
              public  var article_panel:panel_article;
         
            private function article_popup(id:String,title:String,content:String,writtenby:String):Function
            {
            	
              return function(mouseEvent:MouseEvent):void

             {
             	showpanel(id,title,content,writtenby);
             };

            	  
            } 
            private function showpanel(id:String,title:String,content:String,writtenby:String)
            {
              article_panel=new panel_article();
              PopUpManager.addPopUp(article_panel,this,true);
             article_panel.article_content.htmlText=content;
              article_panel.writtenby.htmlText=writtenby;
              article_panel.title=title;
             
             
           
            }
            // get articles articles
            
            public function get_user_articles():void{
            	var res = articlespost.lastResult.toString();
            	//Alert.show(res);
           		switch (res)
           		{
           			case 'success':
			           			Alert.show('Article Posted Successfully');
			            		richtexteditor0.text = '';
			            		articletitle.text = '';
			            		post_article0.label = "Post Article";
			            		post_article0.enabled = true;
			            		currentState = "articles";
			            		
			            		break;
			        case 'notlogin':
			        			Alert.show('Login Session Expired Please login again');
			        			currentState = "home";
			        			break;
			        case 'u_success':
			        			Alert.show('Article Updated Successfully');
			        			richtexteditor0.text = '';
			            		articletitle.text = '';
			        			currentState = "articles";
			        			post_article0.label = "Post Article";
			        			post_article0.enabled = true;
			        			break;
			       	default : 
			        			Alert.show("Error in Article title or Body Please Do not add 's in text"); 
           		} 
             }
            
            // get calender date in articles page 
            
            public function article_date_change(event:CalendarLayoutChangeEvent):void{
            	
            	if (event.currentTarget.selectedDate == null) {
                		return 
            		}
            	var parameters_Sarticle:Object ={};	
            	var date=event.currentTarget.selectedDate.getDate();
            	var month=event.currentTarget.selectedDate.getMonth() + 1;
            	var year=event.currentTarget.selectedDate.getFullYear();
            	parameters_Sarticle['searchdate'] = date+'/'+month+'/'+year;
            	search_article.request=parameters_Sarticle;
            	search_article.send();
				//Alert.show(date+'/'+month+'/'+year);
		
            }
            
            //http result request for get_articles 
            public function get_all_articles():void
            {
            	var res = get_articles.lastResult.articles.item;
            	articles_list.dataProvider = res;
            	
            }
            public function recent_article():void
            {
            	var title:String = recent_artilce.lastResult.item.title;
            	var content:String = recent_artilce.lastResult.item.content;
            	var date:String = recent_artilce.lastResult.item.time;
            	var name:String = recent_artilce.lastResult.item.author;
            	var aid:String = recent_artilce.lastResult.item.aid;
            	var deleting:String = recent_artilce.lastResult.item.del;
            	if(loginval == true)
            	{
	            	if(deleting == 'false')
	            	{
	            	articledel.visible = false;
	            	articleedit.visible = false;
	            	}
	            	else
	            	{
	            	articledel.visible = true;
	            	articleedit.visible = true;
	            	}
	            }
	            else
	            {
	            	articledel.visible = false;
	            	articleedit.visible = false;
	            }
            	article_subject.text = title;
            	article_content.htmlText = content;
            	article_posted.text = 'Posted by '+name+' on '+date;
            	deleteid.label = aid;
            }
            
            public var article_id:int;
            public var parameters_article:Object ={};
            // show articles on list change event
            public function show_article(event:Event):void
            {
            	article_id = event.currentTarget.selectedItem.data;
            	parameters_article['article_id']= article_id;
            	display_article.request=parameters_article;
            	display_article.send();
            }
            
            //to display articles 
            public function displayArticles():void
            {
//            	var sample = display_article.lastResult.toString();
//            	Alert.show(sample);
				if(currentState != "articles")
				 currentState = "articles";
            	var subject:String = display_article.lastResult.item.title;
            	var content:String = display_article.lastResult.item.content;
            	var date:String = display_article.lastResult.item.time;
            	var name:String = display_article.lastResult.item.author;
            	var aid:String = display_article.lastResult.item.aid;
            	if(loginval == true)
            	{
	            	var deleting:String = display_article.lastResult.item.del;
	            	if(deleting == 'true')
	            	{
	            	articledel.visible = true;
	            	articleedit.visible = true;
	            	}
	            	else
	            	{
	            	articleedit.visible = false;
	            	articledel.visible = false;
	            	}
            	}
            	else
            	{
            	articledel.visible = false;
            	articleedit.visible = false;
            	}
            	deleteid.label = aid;
            	article_subject.text = subject;
            	article_content.htmlText = content;
            	article_posted.text = 'Posted by '+name+' on '+date;
            }
            
            public function searchArticles():void
            {
            	var temp:String = search_article.lastResult.articles.item.toString();
            	var res:Object = search_article.lastResult.articles.item;
            	if(temp == 'No')
            	Alert.show('No Articles Found');
            	else
            	articles_list.dataProvider = res;
            	
            }
            public var popup_title:panel_login; 
               
            
            private function showLogin()
            {
               popup_title= new panel_login();
               PopUpManager.addPopUp(popup_title,this,true);
               popup_title.nenunnanu_login.addEventListener(MouseEvent.CLICK, login_send);
            }
            private function login_send(event:MouseEvent) 
            { 
            	var parameters_login:Object ={};
            	parameters_login['login']= popup_title.loginid.text;
            	parameters_login['password']= popup_title.password.text;
            	parameters_login['type']= "nenunnanu";
            	login_as_nenunnanu.request=parameters_login;
                
          	    login_as_nenunnanu.send();
          	   
            	
            }
            
            //delete articly by id 
            private function delete_article():void
            {
            	articledel.label = "Processing..";
            	articledel.enabled = false;
            	articleedit.visible = false;
           		var parameters_art:Object ={};
            	parameters_art['aid']= deleteid.label;
            	parameters_art['delete']= 'article';
            	deletearticle.request = parameters_art;
            	deletearticle.send();	
            	
            }
            // on delete of article 
            
            private function on_article_delete():void
            {
            	var res:String = deletearticle.lastResult.toString();
            	articledel.enabled = true;
            	articledel.label = "Delete";
            	get_all_articles();
            	if(res == 'ok')
            	{
            		 get_articles.send();
            		currentState = "deletesuccess";
            	}
            	else
            	{
            		
            	}
            }
            
            // send article id and get article details
            private var editid:String;
            private function send_edit_article_id():void
            {
            	var subj:String = article_subject.text;
            	var content:String = article_content.text;
            	currentState = "writearticle";
            	articletitle.text = subj;
            	richtexteditor0.text = content;
            	post_article0.label = "Update Post";
            	editid = deleteid.label ;
//           		var parameters_art:Object ={};
//            	parameters_art['aid']= deleteid.label;
//            	parameters_art['edit']= 'article';
////            	editarticles.request = parameters_art;
////            	editarticles.send();	
            } 
            
            // edit articles 
            
            private function edit_articles():void 
            {
            	
            }
            private function date_selectable_init():void
            {
            	// article_date.selectableRange = {rangeStart: new Date(2004,0,1),rangeEnd: new Date(2007,0,10)};
				 //article_date.selectableRange = {[{rangeStart: new Date(2009,8,3),rangeEnd: new Date(2009,8,3)},{rangeStart: new Date(2009,8,5),rangeEnd: new Date(2009,8,5)}]};
				//	article_date.selectableRange = [new Date(2009,8,3)];
            }
           private function loggedin()
           {
           	if(login_as_nenunnanu.lastResult.loginid=="failed")
           	{
           		popup_title.nenunnanu_loginfailed.text="Login failed";
           		//Alert.show("login Failed");
           	}
           	else
           	{
           		PopUpManager.removePopUp(popup_title);
           		//loginFailedText.visible = false;
				loginSuccess.visible = true;
				username.visible=true;
				loginform.visible = false;
				loginval = true;
				username.text=login_as_nenunnanu.lastResult.loginid;
				type.text=login_as_nenunnanu.lastResult.type;
				myMenuAccount0.visible = true;
				loginFailedText.visible = false;
			    button3.visible = false;
				button4.visible = false;
				nenunnanu_log_in.visible=false;
				forgotpw.visible=false;
				ProfileSrv.send();
				
           	} 
           }
